$(function(){
    $('.input_phone').val('');
    $('.input_email').val('');
    var tipsObj = {
        'email': '请输入正确的邮箱',
        'phone': '请输入正确的手机号',
    };
    var rid = '';
    var url = window.location.href;
    if (url.indexOf('rid=') != -1) {
        rid = url.split('rid=')[1];
    }
    /*确认提交*/
    $('.confirm').click(function (e) {
        // window.location.href = './show.html';
        if (rid) {
            //var isEmail = checkEmail();
            //var isPhone = checkPhone();
            //if (isEmail && isPhone) {
        	var phone = $('.input_phone').val();
        	var email = $('.input_email').val();
                /*发送ajax请求*/
                $.ajax({
                    url: './i/home/image/liaison',
                    type: 'POST',
                    data: { rid: rid, phone: phone, email: email},
                    error: function(error){

                    },
                    success: function(data) {
                        if (data.error_code == 0) {
                            alert('信息提交成功');
                            window.location.href = './show.html';
                        } else {
                            alert(data.error_msg);
                        }
                        $('.input_phone').val('');
                        $('.input_email').val('');
                    }
                })
            //}
        } else {
            alert('图像rid不能为空')
        }
    })

    /*校验邮箱和手机值是否合理*/

    //邮箱和手机正则表达
    var regExp = {
        // email:/^\w+@\w+\.\w+$/,
        email: /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-_]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/,
        mobile: /^1(3|4|5|7|8)\d{9}$/
    }
    function checkEmail() {
        var $input_email = $('.input_email')
        var value = $input_email.val();
        if (!value || !regExp.email.test(value)) {
            $input_email.css('border-color', "#f5222d").siblings('div.error_explain').html(tipsObj['email']);
            return false;
        }
        $input_email.css('border-color', "rgb(171,168,168)").siblings('div.error_explain').html('');
        return true;
    }
    function checkPhone() {
        var $input_phone = $('.input_phone')
        var value = $input_phone.val();
        if (!value || !regExp.mobile.test(value)) {
            $input_phone.css('border-color', "#f5222d").parents('.input_phone_special').siblings('div.error_explain').html(tipsObj['phone']);
            return false;
        }
        $input_phone.css('border-color', "rgb(171,168,168)").parents('.input_phone_special').siblings('div.error_explain').html('');
        return true;
    }

    $(".container .main .back").click(function(){
        window.location.href = './home.html';
    })
})